package com.cat.greedyAlgorithm;

import java.util.Arrays;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/eat-pizzas/description/
 * @create 2025/8/22 16:58
 * @since JDK17
 */

public class Solution17 {
    public long maxWeight(int[] pizzas) {
        int n = pizzas.length, odd = (n / 4 + 1) / 2, even = n / 8;
        long ans = 0;
        Arrays.sort(pizzas);

        for (int i = 0; i < odd; i++) { // 先选奇数
            ans += pizzas[n - 1 - i];
        }

        for (int i = 0; i < even; i++) {
            ans += pizzas[n - 2 - odd - i * 2];
        }
        return ans;
    }
}
